import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-16
 * Time: 22:28
 */
public class Demo1 {
    public static void main(String[] args) {
        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            //TimerTask 相当于Runnable
            @Override
            public void run() {
                System.out.println("hello 5000");
            }
        },5000);//5000ms后执行
        /**
         * delay :表示"多长时间后执行,以当前执行"schedule"的时刻为基准
         * 继续等delay时间之后再去进一步的执行
         *
         */
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello 1000");
            }
        },1000);//1000ms后执行
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello 3000");
            }
        },3000);//3000ms后执行


    }
}
